﻿using KalevaAalto.DataPart.Excel.Base;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KalevaAalto.DataPart.Excel.Epplus
{
    internal class EpplusWorkbook : BaseWorkbook
    {
        private ExcelPackage _package;
        public override BaseWorksheets Worksheets => new EpplusWorksheets(this,_package.Workbook.Worksheets);

        public EpplusWorkbook() { _package = new ExcelPackage(); }
        public EpplusWorkbook(string fileName) { _package = new ExcelPackage(fileName); }

        public override void Save()
            =>_package.Save();
        

        public override void SaveAs(string fileName)
            =>_package.SaveAs(fileName);
        
        public override async Task SaveAsync(CancellationToken token)
            =>await _package.SaveAsync(token);
        

        public override async Task SaveAsAsync(string fileName, CancellationToken token)
            =>await _package.SaveAsAsync(fileName, token);
        

        public override byte[] ToBytes()
            => _package.GetAsByteArray();
        

        public override async Task<byte[]> ToBytesAsync(CancellationToken token)
            => await _package.GetAsByteArrayAsync(token);

        public override void Dispose()
        {
            _package.Dispose();
        }

    }
}
